import 'package:flutter/material.dart';

class HeroDemo extends StatelessWidget {

  _to(context){
    //打开B路由
    Navigator.push(context, PageRouteBuilder(
      pageBuilder: (BuildContext context, Animation animation,
                    Animation secondaryAnimation) {
        return new FadeTransition(
          opacity: animation,
          child: Scaffold(
            appBar: AppBar(
              title: Text("原图"),
            ),
            body: HeroAnimationRouteB(),
          ),
        );
      })
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Hero 动画"),
      ),
      body: Container(
        child: Center(
          child: InkWell(
            child: Hero(
              tag: "avatar", //唯一标记，前后两个路由页Hero的tag必须相同
              child: ClipOval(
                child: Image.asset("assets/images/beach1.jpg",
                  width: 100.0,
                ),
              ),
            ),
            onTap: () {
              _to(context);
            },
          ),
        ),
      ),
    );
  }
}

class HeroAnimationRouteB extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Hero(
      tag: "avatar", //唯一标记，前后两个路由页Hero的tag必须相同
      child: Image.asset("assets/images/beach1.jpg"),
    );
  }
}